const StudentModel = require('../db/models/student');

class StudentService {
    //爬取学生信息
    async addStudentData (data) {
        const sid = data.sid;

        const result = await StudentModel.findOne({
            where: { sid }
        });

        if (result) {
            return await StudentModel.update(data, {
                where: { sid }
            })
        } else {
            return await StudentModel.create(data);
        }
    }

    //获取学生信息
    async getStudentData () {
        return await StudentModel.findAll({
            attributes: {
                exclude: ['studentImg']
            }
        })
    }

    //改变学生上下架状态
    async changeStudentStatus (id, status) {
        const ret = await StudentModel.update( { status }, {
            where: { id }
        });

        return ret[0];
    }
}

module.exports = new StudentService();